// upsystem/public/js/menu.js
frappe.pages['desk'].on_page_load = function(wrapper) {
    var page = frappe.ui.make_app_page({
        parent: wrapper,
        title: __('Upsystem'),
        single_column: true
    });

    // Add menu item
    frappe.provide('frappe.desk.menu');
    frappe.desk.menu.add_sidebar_item('My ERPNext Page', function() {
        frappe.set_route('upsystem', 'my_erpnext_page');
    }, 'Upsystem');

    // Ensure the module is added to the sidebar
    setTimeout(function() {
        var module = $('.module-item:contains("Upsystem")');
        if (module.length === 0) {
            frappe.desk.menu.add_module('Upsystem', '/upsystem');
        }
    }, 1000);
};

// Also add to website menu
frappe.ready(function() {
    if (frappe.session.user !== 'Guest') {
        var website_menu = $('.navbar-nav');
        var upsystem_menu = website_menu.find('li:contains("Upsystem")');

        if (upsystem_menu.length === 0) {
            website_menu.append(
                '<li class="nav-item dropdown">' +
                '    <a href="#" class="nav-link dropdown-toggle" data-toggle="dropdown">Upsystem</a>' +
                '    <div class="dropdown-menu">' +
                '        <a href="/upsystem/my_erpnext_page" class="dropdown-item">My ERPNext Page</a>' +
                '    </div>' +
                '</li>'
            );
        }
    }
});